package leetcode;

public class LeetCode11 {

    //冒泡 暴力解法
    public int maxArea1(int[] height) {
        int max = 0;
        for (int i = 0; i < height.length; i++) {
            for (int j = i + 1; j < height.length; j++) {
                max = Math.max(max, getArea(i, height[i], j, height[j]));
            }
        }
        return max;
    }

    private int getArea(int x1, int y1, int x2, int y2) {
        return (x2 - x1) * Math.min(y1, y2);
    }
//------------------------------------------------------------------

    //双指针算法
    public int maxArea(int[] height) {
        int max = 0, left = 0, right = height.length - 1;
        while (left < right) {
            max = Math.max(max, (right - left) * Math.min(height[right], height[left]));
            if (height[right] > height[left])
                left++;
            else
                right--;
        }
        return max;
    }
}
